4d60073ec03650f0f91952aaffa95027b613eb41,src/main/java/de/dynamicfiles/projects/gradle/plugins/javafx/tasks/workers/JfxNativeWorker.java,JfxNativeWorker,jfxnative,#Project#,65
Before Change
String bundler = ext.getBundler();
final Logger logger = project.getLogger();
workarounds = new Workarounds(new File(project.getProjectDir(), ext.getNativeOutputDir()), logger);
Map<String, ? super Object> params = new HashMap<>();
After Change
private Workarounds workarounds = null;
public void jfxnative(Project project) {
// get our configuration
JavaFXGradlePluginExtension ext = project.getExtensions().getByType(JavaFXGradlePluginExtension.class);
addDeployDirToSystemClassloader(project, ext);
String bundler = ext.getBundler();
final Logger logger = project.getLogger();
workarounds = new Workarounds(getAbsoluteOrProjectRelativeFile(project, ext.getNativeOutputDir(), ext.isCheckForAbsolutePaths()), logger);
Map<String, ? super Object> params = new HashMap<>();
logger.info("Creating parameter-map for bundler '" + bundler + "'");
params.put(StandardBundlerParam.VERBOSE.getID(), ext.isVerbose());
Optional.ofNullable(ext.getIdentifier()).ifPresent(id -> {
params.put(StandardBundlerParam.IDENTIFIER.getID(), id);
});
// on gradle we don't have nice appnames .... i think?!
String appName = ext.getAppName();
if( appName == null ){
org.gradle.api.tasks.bundling.Jar jarTask = (org.gradle.api.tasks.bundling.Jar) project.getTasks().findByName("jar");
String archiveName = jarTask.getArchiveName();
appName = archiveName.substring(0, archiveName.lastIndexOf("."));
}
params.put(StandardBundlerParam.APP_NAME.getID(), appName);
params.put(StandardBundlerParam.VERSION.getID(), ext.getNativeReleaseVersion());
if( ext.getVendor() == null ){
throw new GradleException("You have to set a vendor, which is required for bundlers.");
}
params.put(StandardBundlerParam.VENDOR.getID(), ext.getVendor());
params.put(StandardBundlerParam.SHORTCUT_HINT.getID(), ext.isNeedShortcut());
params.put(StandardBundlerParam.MENU_HINT.getID(), ext.isNeedMenu());
params.put(StandardBundlerParam.MAIN_CLASS.getID(), ext.getMainClass());
Optional.ofNullable(ext.getJvmProperties()).ifPresent(jvmProps -> {
params.put(StandardBundlerParam.JVM_PROPERTIES.getID(), new HashMap<>(jvmProps));
});
Optional.ofNullable(ext.getJvmArgs()).ifPresent(jvmOptions -> {
params.put(StandardBundlerParam.JVM_OPTIONS.getID(), new ArrayList<>(jvmOptions));
});
Optional.ofNullable(ext.getUserJvmArgs()).ifPresent(userJvmOptions -> {
params.put(StandardBundlerParam.USER_JVM_OPTIONS.getID(), new HashMap<>(userJvmOptions));
});
Optional.ofNullable(ext.getLauncherArguments()).ifPresent(arguments -> {
params.put(StandardBundlerParam.ARGUMENTS.getID(), new ArrayList<>(arguments));
});
Optional.ofNullable(ext.getAdditionalAppResources())
.filter(appRessourcesString -> appRessourcesString != null)
.map(appRessourcesString -> getAbsoluteOrProjectRelativeFile(project, appRessourcesString, ext.isCheckForAbsolutePaths()))
.filter(File::exists)
.ifPresent(appResources -> {
logger.info("Copying additional app ressources...");
try{
Path targetFolder = getAbsoluteOrProjectRelativeFile(project, ext.getJfxAppOutputDir(), ext.isCheckForAbsolutePaths()).toPath();
Path sourceFolder = appResources.toPath();
Files.walkFileTree(appResources.toPath(), new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path subfolder, BasicFileAttributes attrs) throws IOException {
// do create subfolder (if needed)
Files.createDirectories(targetFolder.resolve(sourceFolder.relativize(subfolder)));
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
// do copy
Files.copy(sourceFile, targetFolder.resolve(sourceFolder.relativize(sourceFile)), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path source, IOException ioe) throws IOException {
// don't fail, just inform user
logger.warn(String.format("Couldn't copy additional app resource %s with reason %s", source.toString(), ioe.getLocalizedMessage()));
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path source, IOException ioe) throws IOException {
// nothing to do here
return FileVisitResult.CONTINUE;
}
});
} catch(IOException e){
logger.warn("Couldn't copy additional application resource-file.", e);
}
});
// adding all resource-files
Set<File> resourceFiles = new HashSet<>();
try{
Files.walk(getAbsoluteOrProjectRelativeFile(project, ext.getJfxAppOutputDir(), ext.isCheckForAbsolutePaths()).toPath())
.map(p -> p.toFile())
.filter(File::isFile)
.filter(File::canRead)
.forEach(f -> {
logger.info(String.format("Add %s file to application resources.", f));
resourceFiles.add(f);
});
} catch(IOException e){
logger.warn("There was a problem while processing application files.", e);
}
params.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(getAbsoluteOrProjectRelativeFile(project, ext.getJfxAppOutputDir(), ext.isCheckForAbsolutePaths()), resourceFiles));
Collection<String> duplicateKeys = new HashSet<>();
Optional.ofNullable(ext.getBundleArguments()).ifPresent(bArguments -> {